
#define Modbus_Variable
#include "userDef.h"

#ifdef CTRL_485
comm485_typeDef comm485;


void Comm485_Tx( U8 * tx_buf, U16 tx_num ) /* wifi通讯发送 */

{
    // IO_485EN_ON;
    comm485.tx_address = tx_buf;
    comm485.tx_count = tx_num;
    Comm485_Tx_Intp();
}


void Comm485_Tx_Intp( void ) /* wifi通讯发送中断 */
{
    if ( comm485.tx_count > 0 )
    {
        SCI0->TXD1 = *comm485.tx_address;
        comm485.tx_address++;
        comm485.tx_count--;
    }
    else 
    {
        Comm485_Rx( comm485.Cache, LENGTH_485_Cache );
    }
}


void Comm485_Rx( U8 * rx_buf, U16 rx_num ) /* wifi通讯接收 */
{
    // IO_485EN_OFF;
    memset( comm485.Cache, 0, sizeof( comm485.Cache ) );
    comm485.rx_count = 0U;
    comm485.rx_length = rx_num;
    comm485.rx_address = rx_buf;
}


void Comm485_Rx_Intp( U8 data ) /* wifi通讯接收中断 */
{
    if ( comm485.rx_length > comm485.rx_count )
    {
        *comm485.rx_address = data;
        comm485.rx_address++;
        comm485.rx_count++;
        comm485.timeout_rxd = 20;
    }
}


void Comm485Act( void )
{
    if ( comm485.timeout_rxd == 0 && comm485.rx_count > 0 ) /* 接收完一包数据 */
    {
        // IO_485EN_ON;
        comm485.rx_count = 0;
        if ( Comm485_Rxd_Check() ) /* CRC校验正确 */
        {
            switch ( comm485.Cache[1] )
            {
                case READ_HOLDING_REGISTERS:
                    Comm485_Reply_03();
                    break;

                case WRITE_MULTIPLE_REGISTERS:
                    Comm485_Reply_10();
                    break;

                default:
                    Comm485_Rx( comm485.Cache, LENGTH_485_Cache );
                    break;
            }

            timer_wireCtrl_err = 60;    /* 60s无通讯报故障 */
            f_comm485Err = OFF;         /* 清除通讯故障 */
        }
        else 
        {
            Comm485_Rx( comm485.Cache, LENGTH_485_Cache );
        }
    }
}


U8 Comm485_Rxd_Check( void )
{
    U16     length_crc;

    if ( comm485.Cache[0] == ADRR_COMM485_SLAVE && comm485.Cache[1] == READ_HOLDING_REGISTERS ) /* 03功能码--读保持寄存器 */
    {
        length_crc = 6;
    }
    else if ( comm485.Cache[0] == ADRR_COMM485_SLAVE && comm485.Cache[1] == WRITE_MULTIPLE_REGISTERS ) /* 10功能码--写多个保持寄存器 */
    {
        length_crc = ( U16 )
        comm485.Cache[6] +7;
    }
    else 
    {
        return FALSE;
    }

    comm485.checkSum.word = GetCRC16( comm485.Cache, length_crc ); /* 计算crc校验码 */
    if ( comm485.checkSum.hl_byte.H8 == comm485.Cache[length_crc] && comm485.checkSum.hl_byte.L8 == comm485.Cache[length_crc + 1] )
    {
        return TRUE;
    }
    else 
    {
        return FALSE;
    }
}


void Comm485_Reply_03( void )
{
    U8      i;
    U8      error = 0;
    U8      read_sp = 0;
    U16     length_read_byte;
    U16     length_read_word;
    ram_word adrress;

    adrress.hl_byte.H8 = comm485.Cache[2];
    adrress.hl_byte.L8 = comm485.Cache[3];
    length_read_word = comm485.Cache[5];
    if ( length_read_word < 128 )
    {
        length_read_byte = length_read_word * 2;
    }
    else 
    {
        length_read_byte = length_read_word;
        length_read_word = length_read_byte / 2;
    }

    memset( comm485.Cache, 0, sizeof( comm485.Cache ) );
    if ( length_read_word >= 1 && length_read_word <= 127 )
    {
        if ( adrress.word >= ADRRESS_485_REGISTER_0000 && ( adrress.word + length_read_word ) <= ( ADRRESS_485_REGISTER_0000 + LENGTH_485_REGISTER_0000 ) )
        {
            Comm485_0000_Register_Read();
            read_sp = ( adrress.word - ADRRESS_485_REGISTER_0000 ) * 2;
            for ( i = 0; i < length_read_byte; i++ )
            {
                comm485.Cache[3 + i] = comm485.Register_0000[read_sp + i];
            }
        }
        else if ( adrress.word >= ADRRESS_485_REGISTER_0400 && ( adrress.word + length_read_word ) <= ( ADRRESS_485_REGISTER_0400 + LENGTH_485_REGISTER_0400 ) )
        {
            Comm485_0400_Register_Read();
            read_sp = ( adrress.word - ADRRESS_485_REGISTER_0400 ) * 2;
            for ( i = 0; i < length_read_byte; i++ )
            {
                comm485.Cache[3 + i] = comm485.Register_0400[read_sp + i];
            }
        }
        else if ( adrress.word >= ADRRESS_485_REGISTER_0800 && ( adrress.word + length_read_word ) <= ( ADRRESS_485_REGISTER_0800 + LENGTH_485_REGISTER_0800 ) )
        {
            Comm485_0800_Register_Read();
            read_sp = ( adrress.word - ADRRESS_485_REGISTER_0800 ) * 2;
            for ( i = 0; i < length_read_byte; i++ )
            {
                comm485.Cache[3 + i] = comm485.Register_0800[read_sp + i];
            }
        }
        else 
        {
            error   = 0x02;
        }
    }
    else 
    {
        error   = 0x03;
    }

    if ( error == 0 )
    {
        comm485.Cache[0] = ADRR_COMM485_SLAVE;
        comm485.Cache[1] = READ_HOLDING_REGISTERS;
        comm485.Cache[2] = length_read_byte;
        length_read_byte += 3;
    }
    else 
    {
        comm485.Cache[0] = ADRR_COMM485_SLAVE;
        comm485.Cache[1] = READ_HOLDING_REGISTERS | 0x80;
        comm485.Cache[2] = error;
        length_read_byte = 3;
    }

    comm485.checkSum.word = GetCRC16( comm485.Cache, length_read_byte );
    comm485.Cache[length_read_byte++] = comm485.checkSum.hl_byte.H8;
    comm485.Cache[length_read_byte++] = comm485.checkSum.hl_byte.L8;
    Comm485_Tx( comm485.Cache, length_read_byte );
}


void Comm485_Reply_10( void )
{
    U8      i;
    U8      error = 0;
    U8      write_sp = 0;
    U8      length_write_byte;
    U8      length_write_word;
    ram_word adrress;

    adrress.hl_byte.H8 = comm485.Cache[2];
    adrress.hl_byte.L8 = comm485.Cache[3];
    length_write_word = comm485.Cache[5];
    length_write_byte = comm485.Cache[6];
    if ( length_write_word >= 1 && length_write_word <= 127 && ( length_write_word * 2 ) == length_write_byte )
    {
        if ( adrress.word >= ADRRESS_485_REGISTER_0800 && ( adrress.word + length_write_word ) <= ( ADRRESS_485_REGISTER_0800 + LENGTH_485_REGISTER_0800 ) )
        {
            if ( update_wireCtrl == 0 )
            {
                write_sp = ( adrress.word - ADRRESS_485_REGISTER_0800 ) * 2;
                for ( i = 0; i < length_write_byte; i++ )
                {
                    comm485.Register_0800[write_sp + i] = comm485.Cache[7 + i];
                }

                Comm485_0800_Register_Write();
            }
            else 
            {
                error   = 0x04;
            }
        }
        else 
        {
            error   = 0x02;
        }
    }
    else 
    {
        error   = 0x03;
    }

    memset( comm485.Cache, 0, sizeof( comm485.Cache ) );
    if ( error == 0 )
    {
        comm485.Cache[0] = ADRR_COMM485_SLAVE;
        comm485.Cache[1] = WRITE_MULTIPLE_REGISTERS;
        comm485.Cache[2] = adrress.hl_byte.H8;
        comm485.Cache[3] = adrress.hl_byte.L8;
        comm485.Cache[4] = 0x00;
        comm485.Cache[5] = length_write_word;
        length_write_byte = 6;
    }
    else 
    {
        comm485.Cache[0] = ADRR_COMM485_SLAVE;
        comm485.Cache[1] = WRITE_MULTIPLE_REGISTERS | 0x80;
        comm485.Cache[2] = error;
        length_write_byte = 3;
    }

    comm485.checkSum.word = GetCRC16( comm485.Cache, length_write_byte );
    comm485.Cache[length_write_byte++] = comm485.checkSum.hl_byte.H8;
    comm485.Cache[length_write_byte++] = comm485.checkSum.hl_byte.L8;
    Comm485_Tx( comm485.Cache, length_write_byte );
}


void Comm485_0000_Register_Read( void ) /* called in sysInit.c */
{
    U8      TEMPA;

    memset( comm485.Register_0000, 0, sizeof( comm485.Register_0000 ) );
    comm485.Register_0000[0] = 0x01;
    comm485.Register_0000[1] = 0x03;
    comm485.Register_0000[2] = 0x80;

    // word 0 : 2 * 0 + 0[1]
    comm485.Register_0000[2 * 0 + 0] = 0x11; /* 普通空调，壁挂机 */
    comm485.Register_0000[2 * 0 + 1] = 0x80; /* 建立通讯 */

    // word 1 : 2 * 1 + 0[1]
    WRITE_BIT7( comm485.Register_0000[2 * 1 + 1], f_coldOnly ); /* 0-冷暖 / 1-冷暖 */
    WRITE_BIT5( comm485.Register_0000[2 * 1 + 1], ~f_inPower ); /* 0-内机供电 / 1-外机供电 */
    WRITE_BIT4( comm485.Register_0000[2 * 1 + 1], f_Power60Hz ); /* 0-50Hz / 1-60Hz */
    comm485.Register_0000[2 * 1 + 1] |= 0x02; /* 200V～240V */

    // WORD 2
    comm485.Register_0000[2 * 2 + 0] |= parameter_out.indoorNum; /* 外机类型 */
    comm485.Register_0000[2 * 2 + 1] |= parameter_out.comp_type; /* 品牌和冷媒 */

    // WORD 3
    TEMPA   = parameter_out.ofan_type;
    comm485.Register_0000[2 * 3 + 1] |= ( TEMPA & 0x07 ) + ( ( TEMPA & 0x08 ) << 1 ) + ( ( TEMPA & 0x10 ) << 1 );

    // word 4 : 2 * 4 + 0[1]
    comm485.Register_0000[2 * 4 + 1] |= 0x02; /* 有自清洁 */

    // WORD 5 ~ 7
    comm485.Register_0000[2 * 5 + 0] |= OUT_BOARD_CODING_0;
    comm485.Register_0000[2 * 5 + 1] |= OUT_BOARD_CODING_1;
    comm485.Register_0000[2 * 6 + 0] |= OUT_BOARD_CODING_2;
    comm485.Register_0000[2 * 6 + 1] |= OUT_BOARD_CODING_3;
    comm485.Register_0000[2 * 7 + 0] |= OUT_BOARD_CODING_4;
    comm485.Register_0000[2 * 7 + 1] |= 0;

    // WORD 8 ~ 10
    comm485.Register_0000[2 * 8 + 0] |= OUT_PROGRAM_CODING_0;
    comm485.Register_0000[2 * 8 + 1] |= OUT_PROGRAM_CODING_1;
    comm485.Register_0000[2 * 9 + 0] |= OUT_PROGRAM_CODING_2;
    comm485.Register_0000[2 * 9 + 1] |= OUT_PROGRAM_CODING_3;
    comm485.Register_0000[2 * 10 + 0] |= 0;
    comm485.Register_0000[2 * 10 + 1] |= 0;

    // WORD 11 ~ 12
    comm485.Register_0000[2 * 11 + 0] |= EEPROM_CODING_0;
    comm485.Register_0000[2 * 11 + 1] |= EEPROM_CODING_1;
    comm485.Register_0000[2 * 12 + 0] |= EEPROM_CODING_2;
    comm485.Register_0000[2 * 12 + 1] |= EEPROM_CODING_3;

    // WORD 13
    comm485.Register_0000[2 * 13 + 0] |= OUT_PROGRAM_VER;
    comm485.Register_0000[2 * 13 + 1] |= EEPROM_VER;

    // WORD 14
    comm485.Register_0000[2 * 14 + 0] |= Protocol_VER;
    comm485.Register_0000[2 * 14 + 1] |= Valve_Close;

    // WORD 15
    comm485.Register_0000[2 * 15 + 0] |= parameter_out.capacity;

    // word 19 : 2 * 19 + 0[1]
    comm485.Register_0000[2 * 19 + 0] = 0x00;

#ifdef PG_MOTOR
    comm485.Register_0000[2 * 19 + 1] = 0x41; /* 7档风速，PG电机 */

#else

    comm485.Register_0000[2 * 19 + 1] = 0x42; /* 7档风速，DC电机 */
#endif

    // word 21 : 2 * 21 + 0[1]
    comm485.Register_0000[2 * 21 + 0] = 0x00;
    WRITE_BIT4( comm485.Register_0000[2 * 21 + 1], f_eepRom ); /* 0-非记忆 / 1-记忆 */
    comm485.Register_0000[2 * 21 + 1] |= 0x1A; // 0xEA; /* 精确控温、静电除尘、辅热、健康、随身感 */
    if ( Fanmotor_Type == OFF ) // 直流风机
    {
        comm485.Register_0000[2 * 22 + 0] = BOARD_CODING_DC_FAN_0;
        comm485.Register_0000[2 * 22 + 1] = BOARD_CODING_DC_FAN_1;
        comm485.Register_0000[2 * 23 + 0] = BOARD_CODING_DC_FAN_2;
        comm485.Register_0000[2 * 23 + 1] = BOARD_CODING_DC_FAN_3;
        comm485.Register_0000[2 * 24 + 0] = BOARD_CODING_DC_FAN_4;
    }
    else // 交流风机
    {
        comm485.Register_0000[2 * 22 + 0] = BOARD_CODING_AC_FAN_0;
        comm485.Register_0000[2 * 22 + 1] = BOARD_CODING_AC_FAN_1;
        comm485.Register_0000[2 * 23 + 0] = BOARD_CODING_AC_FAN_2;
        comm485.Register_0000[2 * 23 + 1] = BOARD_CODING_AC_FAN_3;
        comm485.Register_0000[2 * 24 + 0] = BOARD_CODING_AC_FAN_4;
    }

    comm485.Register_0000[2 * 24 + 1] = 0x00;
    comm485.Register_0000[2 * 25 + 0] = PROGRAM_CODING_0;
    comm485.Register_0000[2 * 25 + 1] = PROGRAM_CODING_1;
    comm485.Register_0000[2 * 26 + 0] = PROGRAM_CODING_2;
    comm485.Register_0000[2 * 26 + 1] = PROGRAM_CODING_3;
    comm485.Register_0000[2 * 32 + 0] = PROGRAM_VER;
    comm485.Register_0000[2 * 35 + 0] = sysAbility;
    comm485.Register_0000[2 * 36 + 1] = jumpType;
}


void Comm485_0400_Register_Read( void )
{
    ram_word tempA;

    memset( comm485.Register_0400, 0, sizeof( comm485.Register_0400 ) );

    // word 0 : 2 * 0 + 0[1]
    WRITE_BIT7( comm485.Register_0400[2 * 0 + 1], f_OutErr_ALL );
    WRITE_BIT6( comm485.Register_0400[2 * 0 + 1], f_RoomUnitOff );
    if ( b_manual_defrost.set == ON )
    {
        comm485.Register_0400[2 * 0 + 1] |= 0x03; /* 强制化霜 */
    }
    else 
    {
        if ( f_FoRecall == 1 )
        {
            comm485.Register_0400[2 * 0 + 1] |= 0x06; /* 收氟模式 */
        }
        else 
        {
            if ( TestRunStat )
            {
                comm485.Register_0400[2 * 0 + 1] |= 0x07; /* 试运行 */
            }
            else 
            {
                if ( ( CapTestStat || SetFreValue ) )
                {
                    if ( e_mode.run == MODECOOL )
                    {
                        comm485.Register_0400[2 * 0 + 1] |= 0x04; /* 制冷能力测试 */
                    }
                    else 
                    {
                        comm485.Register_0400[2 * 0 + 1] |= 0x05; /* 制热能力测试 */
                    }
                }
            }
        }
    }

    comm485.Register_0400[2 * 0 + 1] |= e_mode.run << 3; /* 模式 */

    // word 2 : 2 * 2 + 0[1]
    comm485.Register_0400[2 * 2 + 0] = SetFreValue; /* 设定频率 */
    comm485.Register_0400[2 * 2 + 1] = parameter_out.comp_freq; /* 实际频率 */

    // word 3 : 2 * 3 + 0[1]
    comm485.Register_0400[2 * 3 + 0] = parameter_out.ofan_speed; /* 外风机1实际转速/10 /档位 */
    comm485.Register_0400[2 * 3 + 1] = 0x00; /* 外风机2实际转速/10 /档位 */

    // word 4 : 2 * 4 + 0[1]
    comm485.Register_0400[2 * 4 + 0] = ( speedNowValue1 & 0xFF00 ) >> 8; /* 室内风机实际转速 */
    comm485.Register_0400[2 * 4 + 1] = speedNowValue1 & 0x00FF; /* 室内风机实际转速 */

    // word 5 : 2 * 5 + 0[1]
    if ( CapTestStat != 0 || ( SetFreValue != 0 && f_TestFanChg == 0 ) )
    {
        comm485.Register_0400[2 * 5 + 0] = 0x07;
    }
    else if ( e_fanStep.run < 5 )
    {
        comm485.Register_0400[2 * 5 + 0] = 0x01;
    }
    else if ( e_fanStep.run < 20 )
    {
        comm485.Register_0400[2 * 5 + 0] = 0x02;
    }
    else if ( e_fanStep.run < 40 )
    {
        comm485.Register_0400[2 * 5 + 0] = 0x03;
    }
    else if ( e_fanStep.run < 60 )
    {
        comm485.Register_0400[2 * 5 + 0] = 0x04;
    }
    else if ( e_fanStep.run < 80 )
    {
        comm485.Register_0400[2 * 5 + 0] = 0x05;
    }
    else if ( e_fanStep.run < 95 )
    {
        comm485.Register_0400[2 * 5 + 0] = 0x06;
    }
    else 
    {
        comm485.Register_0400[2 * 5 + 0] = 0x07;
    }

    comm485.Register_0400[2 * 5 + 1] = e_horSw.set[e_mode.set] << 4; /* 左右扫风角度 */
    comm485.Register_0400[2 * 5 + 1] = e_verSw.set[e_mode.set]; /* 上下扫风角度 */
    tempA.word = parameter_out.eve_value;
    comm485.Register_0400[2 * 6 + 0] = tempA.hl_byte.H8;
    comm485.Register_0400[2 * 6 + 1] = tempA.hl_byte.L8;
    tempA.word = parameter_out.ac_voltage;
    comm485.Register_0400[2 * 8 + 0] = tempA.hl_byte.H8;
    comm485.Register_0400[2 * 8 + 1] = tempA.hl_byte.L8;
    tempA.word = parameter_out.dc_voltage;
    comm485.Register_0400[2 * 9 + 0] = tempA.hl_byte.H8;
    comm485.Register_0400[2 * 9 + 1] = tempA.hl_byte.L8;
    tempA.word = parameter_out.ac_current;
    comm485.Register_0400[2 * 10 + 0] = tempA.hl_byte.H8;
    comm485.Register_0400[2 * 10 + 1] = tempA.hl_byte.L8;
    tempA.word = parameter_out.dc_current;
    comm485.Register_0400[2 * 11 + 0] = tempA.hl_byte.H8;
    comm485.Register_0400[2 * 11 + 1] = tempA.hl_byte.L8;

    // word 13 : 2 * 13 + 0[1]
    comm485.Register_0400[2 * 13 + 0] = ( temp.outdoor & 0xFF00 ) >> 8; /* 室外环境温度 */
    comm485.Register_0400[2 * 13 + 1] = temp.outdoor & 0x00FF; /* 室外环境温度 */

    // word 14 : 2 * 14 + 0[1]
    comm485.Register_0400[2 * 14 + 0] = ( temp.out_tube & 0xFF00 ) >> 8; /* 室外外管温度 */
    comm485.Register_0400[2 * 14 + 1] = temp.out_tube & 0x00FF; /* 室外外管温度 */

    // word 15 : 2 * 15 + 0[1]
    comm485.Register_0400[2 * 15 + 0] = ( temp.out_exha & 0xFF00 ) >> 8; /* 室外排气温度 */
    comm485.Register_0400[2 * 15 + 1] = temp.out_exha & 0x00FF; /* 室外排气温度 */

    // word 16 : 2 * 16 + 0[1]
    comm485.Register_0400[2 * 16 + 0] = ( temp.gas_pipe & 0xFF00 ) >> 8; /* 室外气管温度 */
    comm485.Register_0400[2 * 16 + 1] = temp.gas_pipe & 0x00FF; /* 室外气管温度 */

    // word 17 : 2 * 17 + 0[1]
    comm485.Register_0400[2 * 17 + 0] = ( temp.liquid_pipe & 0xFF00 ) >> 8; /* 室外液管温度 */
    comm485.Register_0400[2 * 17 + 1] = temp.liquid_pipe & 0x00FF; /* 室外液管温度 */

    // word 18 : 2 * 18 + 0[1]
    comm485.Register_0400[2 * 18 + 0] = ( temp.comp_ipm & 0xFF00 ) >> 8; /* 室外IPM模块温度 */
    comm485.Register_0400[2 * 18 + 1] = temp.comp_ipm & 0x00FF; /* 室外IPM模块温度 */

    // word 19 : 2 * 19 + 0[1]
    comm485.Register_0400[2 * 19 + 1] = htu20.hum / 10; /* 室内湿度温度 */

    // word 20 : 2 * 20 + 0[1]
    comm485.Register_0400[2 * 20 + 0] = ( temp.room & 0xFF00 ) >> 8; /* 室内环境温度 */
    comm485.Register_0400[2 * 20 + 1] = temp.room & 0x00FF; /* 室内环境温度 */

    // word 21 : 2 * 21 + 0[1]
    comm485.Register_0400[2 * 21 + 0] = ( temp.tube & 0xFF00 ) >> 8; /* 室内铜管温度 */
    comm485.Register_0400[2 * 21 + 1] = temp.tube & 0x00FF; /* 室内铜管温度 */

    // word 29 : 2 * 29 + 0[1]
    WRITE_BIT7( comm485.Register_0400[2 * 29 + 0], f_HeaterOut ); /* 外机电加热 */
    WRITE_BIT6( comm485.Register_0400[2 * 29 + 0], f_4way ); /* 四通阀 */
    WRITE_BIT5( comm485.Register_0400[2 * 29 + 0], f_ExpRest ); /* 膨胀阀 */
    WRITE_BIT4( comm485.Register_0400[2 * 29 + 0], f_CompOn ); /* 压缩机 */
    if ( parameter_out.ofan_speed > 0 )
    {
        WRITE_BIT2( comm485.Register_0400[2 * 29 + 0], TRUE ); /* 外风机状态 */
    }

    WRITE_BIT1( comm485.Register_0400[2 * 29 + 0], f_Health ); /* 健康状态 */
    WRITE_BIT0( comm485.Register_0400[2 * 29 + 0], f_ctrl_pump ); /* 水泵状态 */
    WRITE_BIT7( comm485.Register_0400[2 * 29 + 1], f_CleanSelf ); /* 自清洁状态 */
    WRITE_BIT6( comm485.Register_0400[2 * 29 + 1], f_outCondensation );
    WRITE_BIT5( comm485.Register_0400[2 * 29 + 1], f_outquiet );
    WRITE_BIT4( comm485.Register_0400[2 * 29 + 1], f_wait );
    WRITE_BIT3( comm485.Register_0400[2 * 29 + 1], f_CoolOilBack | f_HeatOilBack );
    WRITE_BIT2( comm485.Register_0400[2 * 29 + 1], f_Defrosting ); /* 化霜状态 */
    WRITE_BIT1( comm485.Register_0400[2 * 29 + 1], f_Heater ); /* 电加热状态 */

    // word 30 : 2 * 30 + 0[1]
    comm485.Register_0400[2 * 30 + 0] = OutSafeErr1; /* 室外故障标志 */
    comm485.Register_0400[2 * 30 + 1] = OutSafeErr2; /* 室外故障标志 */

    // word 31 : 2 * 31 + 0[1]
    comm485.Register_0400[2 * 31 + 0] = OutSafeErr3; /* 室外故障标志 */
    comm485.Register_0400[2 * 31 + 1] = OutSafeErr4; /* 室外故障标志 */

    // word 32 : 2 * 32 + 0[1]
    comm485.Register_0400[2 * 32 + 0] = OutSafeErr5; /* 室外故障标志 */
    comm485.Register_0400[2 * 32 + 1] = OutSafeErr6; /* 室外故障标志 */

    // word 33 : 2 * 33 + 0[1]
    comm485.Register_0400[2 * 33 + 0] = OutSafeErr7; /* 室外故障标志 */
    comm485.Register_0400[2 * 33 + 1] = OutSafeErr8; /* 室外故障标志 */

    // word 34 : 3 + 2 * 34 + 0[1] = 71[72]
    WRITE_BIT4( comm485.Register_0400[2 * 34 + 1], f_GasSensorErr );
    WRITE_BIT3( comm485.Register_0400[2 * 34 + 1], f_OutErr_UA );
    WRITE_BIT2( comm485.Register_0400[2 * 34 + 1], f_OutCommErr );
    WRITE_BIT1( comm485.Register_0400[2 * 34 + 1], f_FilterClean );
    WRITE_BIT0( comm485.Register_0400[2 * 34 + 1], f_CommErr );

    // word 35 : 3 + 2 * 35 + 0[1] = 73[74]
    if ( l_timerOn.set > 0 ) // && b_timer.set == 1)
    {
        WRITE_BIT7( comm485.Register_0400[2 * 35 + 0], 1 );
    }

    if ( l_timerOff.set > 0 ) // && b_timer.set == 1)
    {
        WRITE_BIT6( comm485.Register_0400[2 * 35 + 0], 1 );
    }

    if ( IO_DOOR_CHECK == 0 )
    {
        WRITE_BIT0( comm485.Register_0400[2 * 35 + 0], 1 );
    }
    else 
    {
        WRITE_BIT0( comm485.Register_0400[2 * 35 + 0], 0 );
    }

    if ( DryerActMin > 0 )
    {
        WRITE_BIT1( comm485.Register_0400[2 * 35 + 0], TRUE );
    }

    WRITE_BIT7( comm485.Register_0400[2 * 35 + 1], f_Humidifier );
    WRITE_BIT4( comm485.Register_0400[2 * 35 + 1], f_SetNoCheckFo );
    if ( stat_AvoidCold <= ACLOW && f_RoomUnitOn == 1 && e_mode.run == MODEHEAT )
    {
        WRITE_BIT3( comm485.Register_0400[2 * 35 + 1], TRUE );
    }
    else 
    {
        WRITE_BIT3( comm485.Register_0400[2 * 35 + 1], FALSE );
    }

    WRITE_BIT1( comm485.Register_0400[2 * 35 + 1], f_Heater );
    WRITE_BIT0( comm485.Register_0400[2 * 35 + 1], f_quickTest );

    // word 36 : 2 * 36 + 0[1]
    WRITE_BIT7( comm485.Register_0400[2 * 36 + 0], f_comm485Err );
    WRITE_BIT6( comm485.Register_0400[2 * 36 + 0], f_waterErr );
    if ( OutSafeErr2 == 0x02 && e_mode.set == MODEHEAT )
    {
        WRITE_BIT4( comm485.Register_0400[2 * 36 + 0], TRUE );
    }

    WRITE_BIT1( comm485.Register_0400[2 * 36 + 0], f_TubeErr || f_TubeErrQT );
    WRITE_BIT0( comm485.Register_0400[2 * 36 + 0], f_RoomErr || f_RoomErrQT );
    WRITE_BIT6( comm485.Register_0400[2 * 36 + 1], f_KeyLock );
    WRITE_BIT5( comm485.Register_0400[2 * 36 + 1], f_HeaterErr );
    WRITE_BIT4( comm485.Register_0400[2 * 36 + 1], f_eepErr );
    WRITE_BIT3( comm485.Register_0400[2 * 36 + 1], f_selErr );
    WRITE_BIT2( comm485.Register_0400[2 * 36 + 1], f_MotorErr );
    WRITE_BIT1( comm485.Register_0400[2 * 36 + 1], f_ZeroErr || f_ZeroErrQT );
    WRITE_BIT0( comm485.Register_0400[2 * 36 + 1], f_JumpErrQT );

    // word 37
    tempA.word = l_timerOn.set + l_timerOff.set;
    comm485.Register_0400[2 * 37 + 0] = tempA.hl_byte.H8;
    comm485.Register_0400[2 * 37 + 1] = tempA.hl_byte.L8;

    //f_OutErr_L1=1;
    //f_OutErr_L2=1;
    //f_OutErr_L3=1;
    //f_OutErr_L4=1;
    //f_OutErr_L5=1;
    //f_OutErr_L6=1;
    //f_OutErr_L7=1;
    //f_OutErr_U1=1;
    //f_OutErr_U2=1;
    //f_OutErr_U4=1;
    //f_OutErr_U6=1;
    //f_OutErr_U7=1;
    //f_OutErr_U8=1;
    ///f_OutErr_U9=1;
    //f_OutErr_UA=1;
    //f_OutErr_Ub=1;
    //f_OutErr_UC=1;
    //f_OutErr_Ud=1;
    //f_OutErr_U0=1;
    // 高位在前 
    WRITE_BIT0( comm485.Register_0400[2 * 38 + 0], f_CommInOut_MB_Err ); //0：正常 ；1：室内外通信故障  E0
    WRITE_BIT1( comm485.Register_0400[2 * 38 + 0], f_OutErr_L1 ); //0：正常 ；1：室外通讯故障 EC
    WRITE_BIT2( comm485.Register_0400[2 * 38 + 0], f_OutErr_L2 ); //0：正常 ；1：室外盘管温度传感器故障 E1
    WRITE_BIT3( comm485.Register_0400[2 * 38 + 0], f_OutErr_L3 ); //0：正常 ；1：系统故障(缺氟) E4
    WRITE_BIT4( comm485.Register_0400[2 * 38 + 0], f_OutErr_L4 ); //0：正常 ；1：机型配置错误 E6
    WRITE_BIT5( comm485.Register_0400[2 * 38 + 0], f_OutErr_L5 ); //0：正常 ；1：室外环境温度传感器故障  E7
    WRITE_BIT6( comm485.Register_0400[2 * 38 + 0], f_OutErr_L6 ); //0：正常；1： 室外排气温度传感器故障 E8
    WRITE_BIT7( comm485.Register_0400[2 * 38 + 0], f_OutErr_L7 ); //0：正常；1： 室外IPM故障  E9
    WRITE_BIT0( comm485.Register_0400[2 * 38 + 1], f_MotorErr ); //0：正常；1：室内风机故障 E5
    WRITE_BIT1( comm485.Register_0400[2 * 38 + 1], f_OutErr_U1 ); //0：正常；1：室外电流传感器故障 EA
    WRITE_BIT2( comm485.Register_0400[2 * 38 + 1], f_OutErr_U2 ); //0：正常；1：室内EEPROM 故障 EE
    WRITE_BIT3( comm485.Register_0400[2 * 38 + 1], 0 ); //0：正常；1：壳顶故障  EP
    WRITE_BIT4( comm485.Register_0400[2 * 38 + 1], f_OutErr_U4 ); //0：正常；1：室外电压传感器故障 EU
    WRITE_BIT5( comm485.Register_0400[2 * 38 + 1], f_OutErr_U5 ); //0：正常；1：吸气传感器故障 EH
    WRITE_BIT6( comm485.Register_0400[2 * 38 + 1], f_OutErr_U6 ); //0：正常；1：电压过低保护 P1
    WRITE_BIT7( comm485.Register_0400[2 * 38 + 1], f_OutErr_U7 ); //0：正常；1：电流过流保护 P2
    WRITE_BIT0( comm485.Register_0400[2 * 39 + 0], f_OutErr_U8 ); //0：正常；1：室外排气温度过高保护 P4
    WRITE_BIT1( comm485.Register_0400[2 * 39 + 0], f_OutErr_U9 ); //0：正常；1：室内盘管制冷过冷保护 P5
    WRITE_BIT2( comm485.Register_0400[2 * 39 + 0], f_OutErr_UA ); //0：正常；1：制热防过热保护 P6
    WRITE_BIT3( comm485.Register_0400[2 * 39 + 0], f_OutErr_Ub ); //0：正常；1：室内盘管制热过热保护  P7
    WRITE_BIT4( comm485.Register_0400[2 * 39 + 0], f_OutErr_UC ); //0：正常；1：室外环境温度过高过低保护  P8
    WRITE_BIT5( comm485.Register_0400[2 * 39 + 0], 0 ); //0：正常；1：压缩机驱动保护  
    WRITE_BIT6( comm485.Register_0400[2 * 39 + 0], f_OutErr_L7 ); //0：正常；1：IPM 保护 E9
    WRITE_BIT7( comm485.Register_0400[2 * 39 + 0], 0 ); //0：正常；1：直流风机保护   
    WRITE_BIT0( comm485.Register_0400[2 * 39 + 1], 0 ); //0：正常；1：内蒸发器出口1传感器故障(IPT出口传感器放在室外时有效)
    WRITE_BIT1( comm485.Register_0400[2 * 39 + 1], 0 ); //0：正常；1：内蒸发器出口2传感器故障(IPT出口传感器放在室外时有效)
    WRITE_BIT2( comm485.Register_0400[2 * 39 + 1], 0 ); //0：正常；1：内蒸发器出口3传感器故障(IPT出口传感器放在室外时有效) 
    WRITE_BIT3( comm485.Register_0400[2 * 39 + 1], 0 ); //0：正常；1：内蒸发器出口4传感器故障(IPT出口传感器放在室外时有效)
    WRITE_BIT4( comm485.Register_0400[2 * 39 + 1], f_OutErr_Ud ); //0：正常；1：压缩机驱动故障 P9
    WRITE_BIT5( comm485.Register_0400[2 * 39 + 1], ( f_TubeErr || f_TubeErrQT ) ); //0：正常；1：室内盘管温故障 E3
    WRITE_BIT6( comm485.Register_0400[2 * 39 + 1], ( f_RoomErr || f_RoomErrQT ) ); //0：正常；1：室内环境传感器故障 E2
    WRITE_BIT7( comm485.Register_0400[2 * 39 + 1], f_OutErr_U0 ); //0：正常；1：室外风机故障 EF
    WRITE_BIT0( comm485.Register_0400[2 * 40 + 0], 0 ); //0：正常；1：
    WRITE_BIT1( comm485.Register_0400[2 * 40 + 0], 0 ); //0：正常；1：
    WRITE_BIT2( comm485.Register_0400[2 * 40 + 0], 0 ); //0：正常；1： 
    WRITE_BIT3( comm485.Register_0400[2 * 40 + 0], 0 ); //0：正常；1：
    WRITE_BIT4( comm485.Register_0400[2 * 40 + 0], 0 ); //0：正常；1：室外EEPROM故障
    WRITE_BIT5( comm485.Register_0400[2 * 40 + 0], f_waterErr ); //0：正常；1：水满保护  FP
    WRITE_BIT6( comm485.Register_0400[2 * 40 + 0], 0 ); //0：正常；1：模块保护 P0
    WRITE_BIT7( comm485.Register_0400[2 * 40 + 0], 0 ); //0：正常；1：显示板与主板通讯故障 Eb
    WRITE_BIT0( comm485.Register_0400[2 * 40 + 1], 0 ); //0：正常；1：
    WRITE_BIT1( comm485.Register_0400[2 * 40 + 1], 0 ); //0：正常；1：
    WRITE_BIT2( comm485.Register_0400[2 * 40 + 1], 0 ); //0：正常；1： 
    WRITE_BIT3( comm485.Register_0400[2 * 40 + 1], 0 ); //0：正常；1：
    WRITE_BIT4( comm485.Register_0400[2 * 40 + 1], 0 ); //0：正常；1：
    WRITE_BIT5( comm485.Register_0400[2 * 40 + 1], 0 ); //0：正常；1：
    WRITE_BIT6( comm485.Register_0400[2 * 40 + 1], 0 ); //0：正常；1：
    WRITE_BIT7( comm485.Register_0400[2 * 40 + 1], 0 ); //0：正常；1：
}


void Comm485_0800_Register_Read( void )
{
    ram_word tempA;
	U16 l_tarTemp_C_set_Cache=0;
	U16 l_tarTemp_F_set_Cache=0;

    // word 32 : 2 * 32 + 0[1]

    /* set power */
    WRITE_BIT7( comm485.Register_0800[2 * 32 + 0], b_power.set );

    /* set light */
    WRITE_BIT6( comm485.Register_0800[2 * 32 + 0], b_light.set );

    /* set mode */
    comm485.Register_0800[2 * 32 + 0] &= 0xC7;
    comm485.Register_0800[2 * 32 + 0] |= e_mode.set << 3;

    /* set fanStep */
    comm485.Register_0800[2 * 32 + 1] &= 0xF0;
    comm485.Register_0800[2 * 34 + 0] &= 0x77;
    if ( e_fanStep.set[e_mode.set] == 0 )
    {
        comm485.Register_0800[2 * 32 + 1] |= 0x00;
    }
    else if ( e_fanStep.set[e_mode.set] < 5 )
    {
        comm485.Register_0800[2 * 34 + 0] |= 0x08;
    }
    else if ( e_fanStep.set[e_mode.set] < 20 )
    {
        comm485.Register_0800[2 * 32 + 1] |= 0x01;
    }
    else if ( e_fanStep.set[e_mode.set] < 40 )
    {
        comm485.Register_0800[2 * 32 + 1] |= 0x02;
    }
    else if ( e_fanStep.set[e_mode.set] < 60 )
    {
        comm485.Register_0800[2 * 32 + 1] |= 0x03;
    }
    else if ( e_fanStep.set[e_mode.set] < 80 )
    {
        comm485.Register_0800[2 * 32 + 1] |= 0x04;
    }
    else if ( e_fanStep.set[e_mode.set] < 95 )
    {
        comm485.Register_0800[2 * 32 + 1] |= 0x05;
    }
    else 
    {
        comm485.Register_0800[2 * 34 + 0] |= 0x80;
    }

    // word 33 : 2 * 33 + 0[1]

    /* set verSwing */
    /* set horSwing */
    comm485.Register_0800[2 * 33 + 1] = e_verSw.set[e_mode.set] + ( e_horSw.set[e_mode.set] << 4 );

    // word 34 : 2 * 34 + 0[1]

    /* set health */
    WRITE_BIT1( comm485.Register_0800[2 * 34 + 0], b_health.set );

    /* set temp unit */
    WRITE_BIT0( comm485.Register_0800[2 * 34 + 0], b_tempFah.set );

    /* set dryer */
    WRITE_BIT7( comm485.Register_0800[2 * 34 + 1], b_dryer.set );

    /* set heater */
    WRITE_BIT6( comm485.Register_0800[2 * 34 + 1], b_heater.set );

    /* set sleep */
    WRITE_BIT5( comm485.Register_0800[2 * 34 + 1], b_sleep.set );

    /* set eco */
    WRITE_BIT4( comm485.Register_0800[2 * 34 + 1], b_eco.set );

    // word 35 : 2 * 35 + 0[1]
    WRITE_BIT3( comm485.Register_0800[2 * 35 + 0], f_CleanSelf );

    /* set lowheat */
    WRITE_BIT6( comm485.Register_0800[2 * 35 + 1], b_lowheat.set );

    // word 45 : 2 * 45 + 0[1]

	l_tarTemp_C_set_Cache=l_tarTemp_C.set[e_mode.set];
	l_tarTemp_F_set_Cache=l_tarTemp_F.set[e_mode.set];
	
	if(l_tarTemp_C_set_Cache>=320)l_tarTemp_C_set_Cache=310;

    /* set target temp */
    if ( b_tempFah.set == 0 )
    {
       // tempA.word = l_tarTemp_C.set[e_mode.set];
		tempA.word =l_tarTemp_C_set_Cache;
    }
    else 
    {
        //tempA.word = ( l_tarTemp_F.set[e_mode.set] -320 ) * 10 / 18;
		 tempA.word = ( l_tarTemp_F_set_Cache -320 ) * 10 / 18;
    }

    comm485.Register_0800[2 * 45 + 0] = tempA.hl_byte.H8;
    comm485.Register_0800[2 * 45 + 1] = tempA.hl_byte.L8;

    // word 46 : 2 * 46 + 0[1]

    /* set timerOn */
    /* set timerOff */
    // if (b_power.set == OFF)
    // {
    //     tempA.word = l_timerOn.set;
    // }
    // else
    // {
    //     tempA.word = l_timerOff.set;
    // }
    // comm485.Register_0800[2 * 46 + 0]  = tempA.hl_byte.H8;
    // comm485.Register_0800[2 * 46 + 1]  = tempA.hl_byte.L8;
    // word 126 : 2 * 126 + 0[1]
    if ( update_wireCtrl > 0 )
    {
        update_wireCtrl--;
        comm485.Register_0800[2 * 126 + 0] = 0x5A;
        comm485.Register_0800[2 * 126 + 1] = 0x5A;
    }
}


void Comm485_0800_Register_Write( void )
{
    ram_word tempA;

    // word 0 : 7 + 2 * 0 + 0[1] = 7[8]
    f_comm485Err = READ_BIT7( comm485.Register_0800[2 * 0 + 0] );
    f_485_room_Err = READ_BIT1( comm485.Register_0800[2 * 0 + 0] );

    // word 11 : 2 * 11 + 0[1]
    tempA.hl_byte.H8 = comm485.Register_0800[2 * 11 + 0];
    tempA.hl_byte.L8 = comm485.Register_0800[2 * 11 + 1];
    temp.wireCtrl = tempA.word;         /* 线控器环温值 */
    timer_room_mode_wireCtrl = 600;     /* 线控器环温有效时间10min */

    // word 32 : 2 * 32 + 0[1]
    if ( READ_BIT6( comm485.Register_0800[2 * 34 + 0] ) == 1 )
    {
        temp.repair = ( comm485.Register_0800[2 * 32 + 1] &0xF0 ) >> 4;
        if ( temp.repair >= 9 )
        {
            temp.repairAct = temp.repair - 16;
        }
    }

    if ( f_CleanSelf == 1 )
    {
        if ( READ_BIT7( comm485.Register_0800[2 * 32 + 0] ) ) /* 收到关机退出自清洁 */
        {
            return;
        }
        else 
        {
            //stat_CleanSelf = CSELF_END;
            CleanSelfMode();
        }
    }

    if ( f_FoRecall == 1 )
    {
        if ( READ_BIT7( comm485.Register_0800[2 * 32 + 0] ) ) /* 收到关机退出收氟 */
        {
            return;
        }
        else 
        {
            f_FoRecall = 0;
        }
    }

    if ( f_FilterClean == TRUE ) /* 收到关机清滤网清洗提醒 */
    {
        if ( READ_BIT7( comm485.Register_0800[2 * 32 + 0] ) )
        {
            ;
        }
        else 
        {
            f_FilterClean = FALSE;
        }
    }

#ifdef DOOR
    if ( ( f_door_check_enable == TRUE && IO_DOOR_CHECK == ON ) || f_door_check_enable == FALSE ) // 门禁功能使能且门卡插入或者门禁功能未使能，才能执行开关机
    {
        /* set power */
        set_power( READ_BIT7( comm485.Register_0800[2 * 32 + 0] ) );
    }
    else if ( f_door_check_enable == TRUE && IO_DOOR_CHECK == OFF )
    {
        /* set power */
        set_power( OFF );
    }

#else // DOOR

    /* set power */
    set_power( READ_BIT7( comm485.Register_0800[2 * 32 + 0] ) );
#endif // DOOR

    /* set light */
    if ( b_light.set == OFF ) //
    {
        set_light( READ_BIT6( comm485.Register_0800[2 * 32 + 0] ) );
    }

    /* set mode */
    set_mode( ( comm485.Register_0800[2 * 32 + 0] &0x38 ) >> 3 );

    /* set eco */
    set_eco( READ_BIT4( comm485.Register_0800[2 * 34 + 1] ) );

    /* set lowheat */
    set_lowheat( READ_BIT6( comm485.Register_0800[2 * 35 + 1] ) );
    f_quickTest = READ_BIT5( comm485.Register_0800[2 * 35 + 0] );
    if ( f_quickTest == 1 )
    {
        quickTest();
    }

    f_SetNoCheckFo = READ_BIT4( comm485.Register_0800[2 * 35 + 0] );

    /* set force defrost */
    if ( b_manual_defrost.set == OFF && ( comm485.Register_0800[2 * 32 + 0] &0x07 ) == 0x03 && TestRunStat == 0 && f_OutErr_Ub == 0 )
    {
        set_manual_defrost( ON );
    }

    /* set fanStep */
    if ( READ_BIT3( comm485.Register_0800[2 * 34 + 0] ) == TRUE ) // word 34
    {
        set_fanStep( FANLEVEL1 );
    }
    else if ( READ_BIT7( comm485.Register_0800[2 * 34 + 0] ) == TRUE ) // word 34
    {
        set_fanStep( FANLEVEL7 );

        // f_wifi_rst = ON; //TEST
    }
    else 
    {
        if ( ( comm485.Register_0800[2 * 32 + 1] &0x0F ) == 0x00 )
        {
            set_fanStep( FANAUTO );
        }
        else if ( ( comm485.Register_0800[2 * 32 + 1] &0x0F ) < 0x06 )
        {
            set_fanStep( ( comm485.Register_0800[2 * 32 + 1] &0x0F ) * 20 - 10 );
        }
        else if ( ( comm485.Register_0800[2 * 32 + 1] &0x0F ) == 0x06 )
        {
            set_fanStep( comm485.Register_0800[2 * 36 + 1] ); // word 36
        }
        else 
        {
            set_fanStep( FANAUTO );
        }
    }

    // word 33 : 2 * 33 + 0[1]

    /* set exp valve */
    if ( READ_BIT7( comm485.Register_0800[2 * 33 + 0] ) == TRUE )
    {
        // word 48 : 2 * 48 + 0[1]
        tempA.hl_byte.H8 = comm485.Register_0800[2 * 48 + 0];
        tempA.hl_byte.L8 = comm485.Register_0800[2 * 48 + 1];
        set_exp_step( tempA.word );
    }

    /* set outfan1 */
    if ( READ_BIT6( comm485.Register_0800[2 * 33 + 0] ) == TRUE )
    {
        // word 39 : 2 * 39 + 0[1]
        if ( comm485.Register_0800[2 * 39 + 0] < 10 )
        {
            tempA.word = ( U16 )
            comm485.Register_0800[2 * 39 + 0] *10;
        }
        else 
        {
            tempA.word = ( U16 )
            comm485.Register_0800[2 * 39 + 0] *20;
        }

        set_out_fan( tempA.word );
    }

    /* set infan1 */
    if ( READ_BIT4( comm485.Register_0800[2 * 33 + 0] ) == TRUE )
    {
        // word 47 : 2 * 47 + 0[1]
        tempA.hl_byte.H8 = comm485.Register_0800[2 * 47 + 0];
        tempA.hl_byte.L8 = comm485.Register_0800[2 * 47 + 1];
        set_in_fan( tempA.word * 10 );
    }

    /* set comp freq */
    if ( READ_BIT3( comm485.Register_0800[2 * 33 + 0] ) == TRUE )
    {
        // word 40 : 2 * 40 + 0[1]
        set_comp_freq( comm485.Register_0800[2 * 40 + 0] );
    }

    /* set exh temperture */
    if ( READ_BIT2( comm485.Register_0800[2 * 33 + 0] ) == TRUE )
    {
        // word 40 : 2 * 40 + 0[1]
        set_exh_temp( comm485.Register_0800[2 * 40 + 1] );
    }

    /* set capacity */
    // if ((comm485.Register_0800[2 * 32 + 0] & 0x07) == 0x04 || (comm485.Register_0800[2 * 32 + 0] & 0x07) == 0x05)
    //{
    //  word 41 : 2 * 41 + 0[1]
    if ( comm485.Register_0800[2 * 41 + 0] <= 10 )
    {
        set_captest( comm485.Register_0800[2 * 41 + 0] );
    }

    //}

    /* set verSwing */
    set_verSw( comm485.Register_0800[2 * 33 + 1] &0x0F );

    /* set horSwing */
    set_horSw( ( comm485.Register_0800[2 * 33 + 1] &0xF0 ) >> 4 );

    // word 34 : 2 * 34 + 0[1]
    room_mode_wireCtrl = ( comm485.Register_0800[2 * 34 + 0] &0x30 ) >> 4;

    /* set health */
    set_health( READ_BIT1( comm485.Register_0800[2 * 34 + 0] ) );

    /* set temp unit */
    set_tempUnit( READ_BIT0( comm485.Register_0800[2 * 34 + 0] ) );

    /* set dryer */
    set_dryer( READ_BIT7( comm485.Register_0800[2 * 34 + 1] ) );

    /* set heater */
    set_heater( READ_BIT6( comm485.Register_0800[2 * 34 + 1] ) );

    /* set sleep */
    set_sleep( READ_BIT5( comm485.Register_0800[2 * 34 + 1] ) );

    // TIMER
    tempA.hl_byte.H8 = comm485.Register_0800[2 * 46 + 0];
    tempA.hl_byte.L8 = comm485.Register_0800[2 * 46 + 1];
    wireCtrl_Timer_min = tempA.word;
    if ( READ_BIT3( comm485.Register_0800[2 * 34 + 1] ) || READ_BIT2( comm485.Register_0800[2 * 34 + 1] ) )
    {
        wireCtrl_Timer = 1;
        if ( READ_BIT3( comm485.Register_0800[2 * 34 + 1] ) ) // 内机板 同步线控器的定时开
        {
            l_timerOn.set = wireCtrl_Timer_min;
        }
        else if ( READ_BIT2( comm485.Register_0800[2 * 34 + 1] ) ) // 内机板 同步线控器的定时关
        {
            l_timerOff.set = wireCtrl_Timer_min;
        }
    }
    else 
    {
        if ( wireCtrl_Timer == 1 )
        {
            l_timerOn.set = 0;
            l_timerOff.set = 0;
        }

        wireCtrl_Timer = 0;
    }

    // word 35 : 2 * 35 + 0[1]
#ifdef DOOR

    /* door check enable */
    if ( READ_BIT7( comm485.Register_0800[2 * 35 + 0] ) == TRUE )
    {
        f_door_check_enable = TRUE;
        EntranceGuard.WireFlag = 1;
        EntranceGuard.DisplayFlag = 1;  // 显示标志
        EntranceGuard.DisplayDelayTime = 0; //显示时间标志
    }
    else 
    {
        f_door_check_enable = FALSE;
        EntranceGuard.WireFlag = 0;
    }

#endif // DOOR

    /* set cleanself */
    if ( READ_BIT3( comm485.Register_0800[2 * 35 + 0] ) == TRUE && f_CleanSelf == 0 )
    {
        if ( temp.roomAct < 160 || temp.roomAct > 380 || temp.outdoor < ( 400 + 0 ) || temp.outdoor > ( 400 + 430 ) || ( temp.roomAct > 300 && temp.outdoor > ( 400 + 400 ) ) )
        {
            ;
        }
        else 
        {
            if ( f_OutCSelf == 1 )
            {
                f_CleanSelf = 1;

                //stat_CleanSelf = CSELF_ACT;
            }
        }
    }

    // word 45 : 2 * 45 + 0[1]
    tempA.hl_byte.H8 = comm485.Register_0800[2 * 45 + 0];
    tempA.hl_byte.L8 = comm485.Register_0800[2 * 45 + 1];

    /* set target temp */
    set_tartemp( tempA.word, ( ( U16 ) ( tempA.word * 1.8 ) + 320 + 4 ) / 5 * 5 );

    // word 46 : 2 * 46 + 0[1]
    // tempA.hl_byte.H8 = comm485.Register_0800[2 * 46 + 0] ;
    // tempA.hl_byte.L8 = comm485.Register_0800[2 * 46 + 1] ;

    /* set timerOn */
    // set_timerOn(tempA.word);

    /* set timerOff */
    // set_timerOff(tempA.word);
    if ( f_chg_power || f_chg_mode || f_chg_tartemp || f_chg_fanstep || f_chg_verSw || f_chg_horSw )
    {
        f_eepRomChg = 1;
        CtrlEndTime = 0;
    }
}


U16 GetCRC16( U8 * buff, U16 length ) /* CRC16校验 */
{
    U8      CrcHi = 0xFF;
    U8      CrcLo = 0xFF;
    U8      Idx;

    while ( length-- )
    {
        Idx     = CrcHi ^ *buff++;
        CrcHi   = CrcLo ^ CRC16_TblHi[Idx];
        CrcLo   = CRC16_TblLo[Idx];
    }

    return ( ( U16 ) ( CrcHi << 8 | CrcLo ) );
}


#endif

